home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 1999 November / SGI IRIX 6.5 Applications 1999 November.iso / dev / insight_dev.idb / usr / share / Insight / bin / glossQA.z / glossQA
Encoding:
Text File  |  1998-10-28  |  3.1 KB  |  114 lines

  1. #!/usr/sbin/perl
  2.  
  3. # the global glossary location
  4.  
  5. if (! $ENV{GLOBAL_GLOSS} ) {
  6.   $GLOBAL_GLOSS="/hosts/bonnie.wpd/depot/doc/1000/007-1859-050/gloss.sgm";
  7. }
  8. else { $GLOBAL_GLOSS = $ENV{GLOBAL_GLOSS} }
  9.  
  10. # test command line syntax
  11. $SGMLFILE=$ARGV[0];
  12. if ($SGMLFILE eq "") {
  13.   print "Usage : glossQA <input-file-name>\n";
  14.   exit;
  15. }
  16.  
  17. # open the sgml file and make lists of all glossitems and b-o-b glossentries
  18. open(F,$SGMLFILE);
  19. while (<F>) {
  20.   while (s/<GLOSSARYITEM>([^<]+)<\/GLOSSARYITEM>/$1/) {
  21.    ($EXPR = $1) =~ s/\\/\\\\/;
  22.    $EXPR =~ s/\(/\\\(/;
  23.    $EXPR =~ s/\)/\\\)/;
  24.    if (!grep(/^$EXPR$/,@GLOSSITEMS)) {
  25.       push(@GLOSSITEMS,"$1");
  26.    }
  27.   }
  28.   if (s/.*<GLOSSARYENTRY>(.*)<\/GLOSSARYENTRY>.*$/$1/) {
  29.     while (s/^(.*)<[^>]+>(.*)$/$1$2/) { ; }
  30.     push(@GLOSSENTRYS,"$1$2");
  31.   }
  32. }
  33. close(F);
  34.  
  35. # see if there are any unresolved items vis-a-vis b-o-b glossentries
  36. foreach $GLOSSITEM (@GLOSSITEMS) {
  37.    ($EXPR = $GLOSSITEM) =~ s/\\/\\\\/;
  38.    $EXPR =~ s/\(/\\\(/;
  39.    $EXPR =~ s/\)/\\\)/;
  40.   if (!grep(/^$EXPR$/,@GLOSSENTRYS)) {
  41.     push(@UNRESOLVEDBOB_ITEMS,$GLOSSITEM);
  42.   }
  43. }
  44.  
  45. # if everything checks, say so and exit
  46. if (@UNRESOLVEDBOB_ITEMS eq "") {
  47.   print "\n Unresolved Glossary terms present in this book: None\n";
  48.   exit;
  49. }
  50.  
  51. # if some items still unresolved open the global gloss, if there is one;
  52. # otherwise, print a list and exit
  53. if (open(F,$GLOBAL_GLOSS)) {
  54.   while (<F>) {
  55.     if (s/.*<GLOSSARYENTRY>(.*)<\/GLOSSARYENTRY>.*$/$1/) {
  56.       while (s/^(.*)<[^>]+>(.*)$/$1$2/) { ; }
  57.       push(@GLOBALGLOSSENTRYS,"$1$2");
  58.     }
  59.   }
  60.   close(F);
  61. }
  62. else {
  63.   print "\n Unresolved Glossary terms present in this book:\n";
  64.   print " -----------------------------------------------\n";
  65.   foreach $UNRESOLVEDBOB_ITEM (@UNRESOLVEDBOB_ITEMS) {
  66.     print " \"$UNRESOLVEDBOB_ITEM\"";
  67.     ($EXPR = $UNRESOLVEDBOB_ITEM) =~ s/\\/\\\\/;
  68.     $EXPR =~ s/\(/\\\(/;
  69.     $EXPR =~ s/\)/\\\)/;
  70.     @MATCHES = grep(/$EXPR/,@GLOSSENTRYS);
  71.     if ($MATCHES[0] ne "") {
  72.       print " matches \"$MATCHES[0]\" (local)"; }
  73.     print "\n";
  74.   }
  75.   exit;
  76. }
  77.  
  78. # see if the global gloss resolves the items unresolved vis-a-vis b-o-b;
  79. # make a list of ones that don't
  80. foreach $UNRESOLVEDBOB_ITEM (@UNRESOLVEDBOB_ITEMS) {
  81.   ($EXPR = $UNRESOLVEDBOB_ITEM) =~ s/\\/\\\\/;
  82.   $EXPR =~ s/\(/\\\(/;
  83.   $EXPR =~ s/\)/\\\)/;
  84.   if (!grep(/^$EXPR$/,@GLOBALGLOSSENTRYS)) {
  85.     push(@UNRESOLVED_ITEMS,$UNRESOLVEDBOB_ITEM);
  86.   }
  87. }
  88.  
  89. # if everything checks, say so
  90. if (@UNRESOLVED_ITEMS eq "") {
  91.   print "\n Unresolved Glossary terms present in this book: None\n";
  92. }
  93. # if some items still unresolved, print them out, plus first grep match
  94. else {
  95.   print "\n Unresolved Glossary terms present in this book:\n";
  96.   print " -----------------------------------------------\n";
  97.   foreach $UNRESOLVED_ITEM (@UNRESOLVED_ITEMS) {
  98.     print " \"$UNRESOLVED_ITEM\"";
  99.     ($EXPR = $UNRESOLVED_ITEM) =~ s/\\/\\\\/;
  100.     $EXPR =~ s/\(/\\\(/;
  101.     $EXPR =~ s/\)/\\\)/;
  102.     @MATCHES = grep(/$EXPR/,@GLOSSENTRYS);
  103.     if ($MATCHES[0] ne "") {
  104.       print " matches \"$MATCHES[0]\" (local)"; }
  105.     else {
  106.       @MATCHES = grep(/$EXPR/,@GLOBALGLOSSENTRYS);
  107.       if ($MATCHES[0] ne "") {
  108.         print " matches \"$MATCHES[0]\" (global)";
  109.       }
  110.     }
  111.   print "\n";
  112.   }
  113. }
  114.